package com.lyn.pluginbazaar.utils;

import java.util.LinkedHashMap;
import java.util.Map;

public class TestUtil {

    static class Cache<K, V> {
        int capacity;
        Map<K, V> map;

        public Cache(int capacity) {
            this.capacity = capacity;
            map = new LinkedHashMap<K, V>(16, 0.75f, true) {

                @Override
                protected boolean removeEldestEntry(Map.Entry eldest) {
                    return size() > capacity;
                }
            };

        }

        public int getCapacity() {
            return capacity;
        }

        public int size() {
            return map.size();
        }

        public V put(K k, V v) {
            return map.put(k, v);
        }

        public V get(K k) {
            return map.get(k);
        }

    }

    public static void printCache(Cache<String, String> cache) {
        cache.map.forEach((k, v) -> {
            System.out.println(k + ":" + v + ",");
        });
        System.out.println();
    }


    public static void main(String[] args) {
//        Cache<String,String> cache=new Cache<>(3);
//        cache.put("a","1");
//        cache.put("b","2");
//        cache.put("c","3");
//        printCache(cache);
//        cache.get("a");
//        cache.get("b");
//        printCache(cache);
//        cache.put("d","4");
//        printCache(cache);

        int[] data = {1, 2, 3,
                4, 5, 6,
                7, 8, 9};
        int[] outData = new int[data.length];
        int index=0;
        int width=3;
        int height=3;
        for (int i = 0; i < width; i++) {
            for (int j = height-1; j >=0; j--) {
                outData[index] = data[j*width+i];
                index+=1;
            }
        }
        for (int i = 0; i < outData.length; i++) {
            System.out.println(outData[i]);
            System.out.println("");
        }
    }


}
